#!/bin/bash

clear


# get eps as argument
while getopts e:f: arg 
do  case "$arg" in
    e)     eps="$OPTARG"
           ;;
    f)     test="$OPTARG"
	   ;; 
    \?)   echo "Usage: $0 [-e ERROR]" >&2 
	  exit 1
           ;;
  esac
done

echo "error : $eps"

if [[ -z "$eps" ]]; then
   echo "Error parameter not specified correctly ... Exiting ..."
   exit 1 
fi



TG_PATH="/home/dseverdi/MATHOS/RADOVI/KOI/TerrainGuarding"
TG_DATA_PATH="$TG_PATH/$test"
echo $TG_DATA_PATH
LOG_PATH="$TG_PATH/logs"



if [ ! -d "$LOG_PATH" ]; then
  mkdir ../logs
fi

TG_SOL="$TG_PATH/TG_solver"
GRB_SOL="$TG_PATH/GRB_PC_solver"


TG="TG"
GRB="GRB"
 
TEST_INPUT="$TG_DATA_PATH/*.in"




# TG solver
if (( $(bc <<< "$eps > 0.0") == 1 ))
then
  for input_file in $TEST_INPUT
  do
    echo "A 5(1+$eps) approximation of 1.5D Terrain Guarding problem on input ${input_file##/*/} ..."
    # process log_file name
    log_file="${TG}_test_${input_file##/*/}_$eps.log"
    $TG_SOL -ILP $input_file -eps $eps -method parallel >& ${LOG_PATH}/$log_file
  done
elif  (( $(bc <<< "$eps == 0.0") == 1 ))
then
  # GRB solver
  for input_file in $TEST_INPUT
  do
   echo "Running GRB ILP solver on input ${input_file##/*/} ..."
   # process log_file name
   log_file="${GRB}_test_${input_file##/*/}.log"
   # find optimal value
   $GRB_SOL -input $input_file -method ILP -type covering >& ${LOG_PATH}/$log_file
  done

  # cleanup
  rm -f $LOG_PATH/PC* $TG_PATH/PC*
fi 

